package cn.service.leave.impl;

import cn.dao.leave.LeaveDao;
import cn.entity.Employee;
import cn.entity.Leave;
import cn.service.leave.LeaveBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service("leaveBiz")
public class LeaveBizImpl implements LeaveBiz {
    @Autowired
    private LeaveDao leaveDao;
    @Override
    public void saveOrUpdate(Leave leave) {
        if (leave.getStatus().equals("已审批")){
            leave.setNextDeal(null);
        }else if ("已打回".equals(leave.getStatus())){
            leave.setNextDeal(leave.getCreator());
        }
        leaveDao.saveOrUpdate(leave);
    }

    @Override
    public long findCountBySn(Employee employee, Date startDate, Date endDate) {
        return leaveDao.findCountBySn( employee, startDate, endDate);
    }

    @Override
    public List<Leave> findBySnAndPage(Employee employee, int indexPage, int pageSize, Date startDate, Date endDate) {
        return leaveDao.findBySnAndPage(employee,indexPage,pageSize,startDate,endDate);
    }

    @Override
    public Leave findById(Long id) {
        return leaveDao.findById(id);
    }

    public LeaveDao getLeaveDao() {
        return leaveDao;
    }

    public void setLeaveDao(LeaveDao leaveDao) {
        this.leaveDao = leaveDao;
    }
}
